"use strict";

angular.module('app.yksensor').controller('YKStoreCtrl', function ($scope,$http,$cookieStore,$rootScope) {
    $http.get("api/project.json").success(function(res){
        console.log(res)
        $scope.projects = res;
    })



    $scope.addStore = function(){
        // console.log('click')
        $('#AddStoreModal').modal('show');
        $scope.newstore = {
            name: "",
            tankid: "",
            type: 1,
            oiltype: "",
            volume: "",
            quality: "",
            level: 0
        }
        $scope.newStore = function(){
            // $('#storeBox').append(
            //     '<div class="well padding-10 store-well pull-left">'+
            //         '<img src="styles/img/store.png" alt="">'+
            //         '<div class="progress_box">'+
            //             '<div class="progress vertical bottom wide-bar" >'+
            //                 '<div class="progress-bar bg-color-teal" data-transitiongoal="'+$scope.newstore.vol+'" aria-valuenow="'+$scope.newstore.vol+'" style="height: '+$scope.newstore.vol+'%; opacity:0.5">'+$scope.newstore.vol+'%</div>'+
            //             '</div>'+
            //         '</div>'+
            //         '<h5 class="text-center margin-top-10 store-name" data-popover-placement="top" data-popover-title="'+$scope.newstore.name+'" data-uib-popover="'+$scope.newstore.type+'">'+$scope.newstore.name+'</h5>' +  
            //     '</div>'
            // )
            var type = $scope.newstore.type == 1 ? "立式钢油罐" : ($scope.newstore.type == 2 ? "卧式钢油罐" : "");
            var img = $scope.newstore.type == 1 ? "拱顶" : ($scope.newstore.type == 2 ? "卧式" : "");
            $("#storeBox").append(
                '<div class="well padding-10 tank-well pull-left text-center" ng-click="viewDetail('+$scope.newstore.tankid+')">'+
                    '<img src="styles/img/tank/'+img+'.jpg" alt="">'+
                    '<a class="tank-name">'+$scope.newstore.name+' 【'+$scope.newstore.tankid+'】</a>'+
                    '<div class="progress_box">'+
                        '<div class="progress vertical bottom" >'+
                            '<div class="progress-bar bg-color-greenLight" data-transitiongoal="'+$scope.newstore.level+'" aria-valuenow="'+$scope.newstore.level+'" style="height: '+$scope.newstore.level+'%; opacity:0.5">'+$scope.newstore.level+'%</div>'+
                        '</div>'+
                    '</div>'+
                    '<table class="table table-bordered">'+
                        '<tbody>'+
                            '<tr><td><b>油罐类型</b></td><td>'+type+'</td></tr>'+
                            '<tr><td><b>储油类型</b></td><td>'+$scope.newstore.oiltype+'</td></tr>'+
                            '<tr><td><b>体积质量</b></td><td>'+$scope.newstore.volume+' m3 / '+$scope.newstore.quality+' t</td></tr>'+
                            '<tr><td><b>当前液位</b></td><td>'+$scope.newstore.level/100*30+' m</td></tr>'+
                            '<tr><td><b>平均温度</b></td><td>20.2 °C</td></tr>'+
                        '</tbody>'+
                    '</table>'+
                '</div>'
            )
        }
        
    }

    $scope.createProject = function () {
        $cookieStore.remove('edit_pid');
        window.location.href = appConfig.base[0].baseURI + "#/add_newProject";
    }

    $scope.viewDetail = function(pid){
        console.log(pid);
        $cookieStore.put('edit_pid', pid);
        // $rootScope.Edit_pro_id = pid;
        // window.location.href = appConfig.base[0].baseURI + "#/yk_storedetail";
        window.location.href = appConfig.base[0].baseURI + "#/add_newProject";//编辑项目
    }
});

